package cn.zjutleo.village_server.controller;

import cn.zjutleo.village_server.annotation.RequiresLogin;
import cn.zjutleo.village_server.config.JwtConfig;
import cn.zjutleo.village_server.dto.JwtPayloadDto;
import cn.zjutleo.village_server.util.JwtUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: 张坤
 * @DateTime: 2022/1/14 14:21
 * @Description: 该类用于 TODO
 */
@Api(tags = "JWT测试类")
@RestController
@RequestMapping("/JWTTest")
public class testJWTcontroller {
    @Resource
    private JwtConfig jwtConfig;

    @RequiresLogin
    @GetMapping("/test1")
    public String testJWT1(){
        return "1111";
    }

    @GetMapping("/test2")
    public String testJWT2(){
        JwtPayloadDto testDto=new JwtPayloadDto();
        testDto.setAccount(123456);
        testDto.setRoleName("超级管理员");
        testDto.setAuthenticated(true);
        testDto.setSignedNotice(true);
        return JwtUtil.sign(testDto,"password=123456",25);
    }
    @GetMapping("/test3/{JWTtoken}")
    public JwtPayloadDto testJWT3(@PathVariable String JWTtoken){
        return JwtUtil.getPayload(JWTtoken);
    }

    @GetMapping("/test4/{JWTtoken}")
    public boolean testJWT4(@PathVariable String JWTtoken){
        JwtPayloadDto testDto=new JwtPayloadDto();
        testDto.setAccount(123456);
        testDto.setRoleName("超级管理员");
        testDto.setAuthenticated(true);
        testDto.setSignedNotice(true);
        return JwtUtil.verify(JWTtoken,testDto,"password=123456");
    }

    @GetMapping("/test5/{JWTtoken}")
    public boolean testJWT5(@PathVariable String JWTtoken){
        JwtPayloadDto testDto=new JwtPayloadDto();
        testDto.setAccount(123456);
        testDto.setRoleName("超级管理员");
        testDto.setAuthenticated(true);
        testDto.setSignedNotice(true);
        return JwtUtil.verify(JWTtoken,testDto,"wrongPassword");
    }
}
